package com.hrhx.duhongming.core;

import java.util.List;
import java.util.Map;

import com.github.abel533.echarts.code.SeriesType;
import com.github.abel533.echarts.json.GsonOption;
import com.hrhx.duhongming.adapter.HighChartsBar3DAdapter;
import com.hrhx.duhongming.adapter.HighChartsPie3DAdapter;
import com.hrhx.duhongming.bean.EchartsConfig;

public class HighChartsCore {
	
	public GsonOption getBaseGsonOption(EchartsConfig echartsConfig){
		//1.获取option对象
		GsonOption gsonOption = new GsonOption();
		//设置标题、设置子标题
		gsonOption.title(echartsConfig.getTitle(),echartsConfig.getSubtitle());
		if("bar3d".equals(echartsConfig.getType())){
			//设置图表属性
			gsonOption.chart()
					  .inverted(false)
					  .type(SeriesType.column)
					  .margin(new int[]{75,75,75,75});
			//设置图表3D属性
			gsonOption.chart().options3d()
							  .enabled(true)
							  .alpha(10)
							  .beta(25)
							  .depth(70);	
			//图表标签显示格式
			gsonOption.plotOptions().column()
									.depth(25)
									.cursor("pointer")
									.dataLabels().enabled(true).format("{point.y:.2f}");
		}else if("pie3d".equals(echartsConfig.getType())){
			//设置3D状态
			gsonOption.chart().options3d().enabled(true).alpha(45).beta(0);
			gsonOption.chart().margin(new int[]{25,25,25,25})
						  .type(SeriesType.pie);
			//工具显示框
			gsonOption.tooltip().pointFormat("{series.name}: <b>{point.percentage:.2f}%</b>");
			//3D饼状图基本配置
			gsonOption.plotOptions().pie().allowPointSelect(true)
									  .cursor("pointer")
									  .depth(35)
									  .dataLabels().enabled(true)
									               .format("<b>{point.name}</b>")//: {point.percentage:.2f}%
									               //.distance(-25)
									               .style("fontWeight: 'bold',color: 'white',textShadow: '0px 1px 2px black'");
		}	
		
		return gsonOption;

	}
	public GsonOption adapterBar3D(EchartsConfig echartsConfig, GsonOption gsonOption,List<Map<String,Object>> data) {
		return HighChartsBar3DAdapter.adapter(echartsConfig,gsonOption,data);
	}
	public GsonOption adapterPie3D(EchartsConfig echartsConfig, GsonOption gsonOption,Map<String, Object> data) {
		return HighChartsPie3DAdapter.adapter(echartsConfig,gsonOption,data);
	}
}
